package com.longcai.piaojia.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.adapter.IntegrationListAdapter;
import com.longcai.piaojia.conn.UserInfoIntegralRecordGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/3.
 */
public class IntegrationGetFragment extends BaseFragment {

    @BoundView(R.id.integration_lv)
    private ListView integration_lv;
    private List<UserInfoIntegralRecordGet.IntegralRecord> lists = new ArrayList<>();

    private IntegrationListAdapter adapter;

    private UserInfoIntegralRecordGet userInfoIntegralRecordGet = new UserInfoIntegralRecordGet(new AsyCallBack<UserInfoIntegralRecordGet.IntegralRecordEntity>(){
        @Override
        public void onSuccess(String toast, int type, UserInfoIntegralRecordGet.IntegralRecordEntity integralRecordEntity) throws Exception {

            lists.addAll(integralRecordEntity.recordList);

            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(getActivity(), toast);
        }
    });

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = BoundViewHelper.boundView(this, inflater.inflate(R.layout.fragment_integration_get, null));

        userInfoIntegralRecordGet.user_id = BaseApplication.BasePreferences.readUserId();
        userInfoIntegralRecordGet.type = "1";
        userInfoIntegralRecordGet.execute(getActivity());

        integration_lv.setDivider(null);
        integration_lv.setAdapter(adapter = new IntegrationListAdapter(getContext(), lists));

        return view;
    }
}
